package com.xliu.csopenproject.pim_server.store;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.nio.file.Files;

@Slf4j
public class LocalFileStore implements ImageStore {

    private final String BASE_PATH = "/images";

    @Override
    public void save(MultipartFile file) throws IOException {
        String name = file.getName();

        file.transferTo(new File(BASE_PATH, name));
    }

    @Override
    public InputStream read(String storeId) throws IOException {
        return Files.newInputStream(new File(BASE_PATH, storeId).toPath());

    }
}
